﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DownloadMag.Core
{
    public class UserInfo
    {
        public UserInfo(string user, string password)
            : this("", user, password)
        {
        }
        public UserInfo(string domain, string user, string password)
        {
            Domain = domain;
            User = user;
            Password = password;
            if (string.IsNullOrEmpty(domain))
            {
                UserInfoString = user + ":" + password;
            }
            else
            {
                UserInfoString = domain + "\\" + user + ":" + password;
            }
        }
        public UserInfo(string strUserInfo)
        {
            UserInfoString = strUserInfo;
            string[] tmp = strUserInfo.Split(':');
            User = tmp[0];
            if (tmp.Length > 1)
            {
                Password = tmp[1];
            }

            int slashIndex = User.IndexOf('\\');

            if (slashIndex >= 0)
            {
                Domain = User.Substring(0, slashIndex);
                User = User.Substring(slashIndex + 1);
            }
        }

        public string UserInfoString { get; private set; }

        public string User { get; private set; }
        public string Domain { get; private set; }
        public string Password { get; private set; }


        public override string ToString()
        {
            return this.UserInfoString;
        }
    }
}
